
type Info struct {
	Id int64
}

// 批量情况
func GetBatch() ([]Info, error) {
	var List []Info

	o := orm.NewOrm()

	_, err := o.Raw("SELECT id FROM data").QueryRows(&List)
	if err != nil {
		return nil, errors.Wrapf(err, "data not found")
	}

	return list, nil
}

// 单个情况
func GetOne(Id int64) (*Info, error) {
	// 如果报错
	var Data Info

	o := orm.NewOrm()

	_, err := o.Raw("SELECT id FROM data WHERE id = '" + strconv.FormatInt(Id, 10) + "'").QueryRow(&Data)
	if err != nil {
		return nil, errors.Wrapf(err, "data not found")
	}

	return &Data, nil
}

func main() {
	var Response map[string]interface{}

	// 批量查询
	List, err := this.GetBatch()
	if err != nil {
		if err != sql.ErrNoRows {
			Response["json"] = map[string]interface{}{"status": 2, "msg": "数据库错误：" + err.Error()}
		}
		Response["json"] = map[string]interface{}{"status": 0, "data": []Info{}}
	} else {
		Response["json"] = map[string]interface{}{"status": 0, "data": List}
	}

	this.ServeJSON()
	this.StopRun()

	// 查询单个
	Data, err := this.GetOne(1)
	if err != nil {
		Response["json"] = map[string]interface{}{"status": 2, "msg": "查询出错：" + err.Error()}
	} else {
		Response["json"] = map[string]interface{}{"status": 0, "data": Data}
	}

	this.ServeJSON()
	this.StopRun()

}

// 作业回答：应该讲错误上抛到最初业务层，但是可以根据数据层的本身业务（批量或单个）来预先筛选错误。